package c3.demo3;

/**
 * 1.this关键字
 *    Student区间内this指Student类本身
 *    使用this可以使用类的其他属性和方法
 * 2.static关键字
 */
class Student {
    public static Student stu1;
    String id;
    String name;
    private int age;
    private int gender;//0男 1女
    String dep = "信息系";
    static String hobby = "健身";
    
    public Student(String ID) {// 方法名称和类名一致 叫做构造方法
        id = ID;
    }


    public Student() {

    }

    void read() {
        System.out.println("大家好，我是" + name + "我在看书");
    }
    void setAge(int age) {//设置年龄
        this.age=age;//Student区间内this指Student类本身
            if (age < 0 || age>150) {
        System.out.println("你输入的年龄有误");
        } else {
        this.age = age;
        }
    }

        int getAge() {//获取年龄
        return age;
        }

        
        void setGender(String g) {
        if (g.equals("男")) {
        gender = 0;
        } else if (g.equals("女")) {
        gender = 1;
        } else {
        System.out.println("性别有误");

        }
        }

        String getGender() {
        if (gender == 0) {
        return "男";
        } else {
        return "女";
        }
        }

    public void setage(int i) {
    }
}
public class Demo3 {
    private static Student stu1;

    public static void main(String[] args) {
        Student.stu1 =new Student();
        stu1.setage(18);
        Student stu2 = new Student();
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        stu1.dep = "宇宙类";
        System.out.println("修改stu1后系部信息");
        System.out.println(stu1.dep);
        System.out.println(stu2.dep);
        System.out.println("***************");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
        stu1.hobby = "抽烟";
        System.out.println("学生1爱好static属性变化");
        System.out.println(stu1.hobby);
        System.out.println(stu2.hobby);
    }
}
